package com.unohacha.qqj.fzdr.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.unohacha.qqj.fzdr.R;

import java.util.List;

public class GridAdapter extends BaseAdapter {
    public LayoutInflater mInflater;
    public Context context;
    public List<String> list;

    public GridAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
        mInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            holder=new ViewHolder();
            convertView=mInflater.inflate(R.layout.item_gv,null);
            holder.iv=convertView.findViewById(R.id.item_gv_home);
            holder.tvname=convertView.findViewById(R.id.item_tv_home);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tvname.setText(list.get(position));
        return convertView;
    }

    class  ViewHolder{
        ImageView iv;
        TextView tvname;
    }
}
